#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = long long;
int mod = 100000000;
void solve()
{
    int n;
    cin >> n;
    vector<int> a(n );
    i64 ans = 0;
    for(int i = 0; i < n; i++)
    {
    	cin >> a[i];
    }
    sort(all(a));
    int cnt = 0;
    for(int i = 0; i < n; i++)
    {
    	ans += (n - 1) * a[i];
    	auto j = lower_bound(a.begin() + i + 1, a.end(), mod - a[i]) - a.begin();
    	//cout << ans << ' ' << j << endl;
    	if(a[i] + a[j] >= mod && i != j)
    	{
    		ans -= (n - j) * mod;
    	}
    }
    cout << ans;

}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}
